package Final;

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.TitledBorder;


public class ClassManager{

    public static void main(String[] args) {

        Runnable r = new Runnable() {

            public void run() {
            	
            	JLabel ClassCodeL = new JLabel("Class Code");
            	JTextField ClassCodeT = new JTextField("Class Code");
            	JLabel ClassDescriptionL = new JLabel("Class Description");
            	JTextField ClassDescriptionT = new JTextField("Class Description");
            	
            	JLabel SeasonCodeL = new JLabel("Season");
            	JTextField SeasonCodeT = new JTextField("Season");
            	JLabel SeasonDescriptionL = new JLabel("Season Description");
            	JTextField SeasonDescriptionT = new JTextField("Season Description");
            	
            	JLabel seasoncodeL = new JLabel("Season");
            	JLabel classcodeL = new JLabel("Class");

            	JTextField AddT = new JTextField("Add Season Code");
            	JTextField AddCodeT = new JTextField("Add Class Code");
            	
            	JButton searchB = new JButton("Search");
            	JLabel newseasonl = new JLabel("Season");
            	JTextField newseasont = new JTextField();
            	JButton addB = new JButton("Add");
            	JButton closeB = new JButton("Close");	
            	JButton deleteB = new JButton("Delete");
            	
        		SeasonCodeL.setBounds(185,105,85,20);		
        		SeasonCodeL.setFont(new Font("arial", Font.PLAIN, 11));
        		SeasonCodeT.setBounds(185,125,65,20);
        		SeasonCodeT.setDocument(new JTextFieldLimit(4));
        		SeasonCodeT.setToolTipText("Enter a Season Code for search");
        		SeasonDescriptionL.setBounds(285, 105, 95, 20);
        		SeasonDescriptionL.setFont(new Font("arial", Font.PLAIN,11));
        		SeasonDescriptionT.setToolTipText("Enter a Search Description for search");
        		SeasonDescriptionT.setBounds(285,125,95,20);
        		SeasonDescriptionT.setDocument(new JTextFieldLimit(11));
        		
        		seasoncodeL.setBounds(185,105,85,20);		
        		seasoncodeL.setFont(new Font("arial", Font.PLAIN, 11));
        		
        		classcodeL.setBounds(185,105,85,20);		
        		classcodeL.setFont(new Font("arial", Font.PLAIN, 11));
        		
            	ClassCodeL.setBounds(25,105,180,20);
        		ClassCodeL.setFont(new Font("arial", Font.PLAIN, 11));
        		
        		ClassCodeT.setBounds(25,125,55,20);
        		ClassCodeT.setDocument(new JTextFieldLimit(2));
        		ClassDescriptionL.setBounds(85,105,150,20);
        		ClassDescriptionL.setFont(new Font("arial", Font.PLAIN, 11));
        		ClassDescriptionT.setBounds(85,125,85,20);
        		ClassDescriptionT.setDocument(new JTextFieldLimit(11));
        		
        		AddT.setFont(new Font("arial", Font.PLAIN,11));
        		AddT.setBounds(85, 125, 45, 20);
        		AddT.setDocument(new JTextFieldLimit(4));
        		
        		AddCodeT.setFont(new Font("arial", Font.PLAIN,11));
        		AddCodeT.setBounds(185, 125, 45, 20);
        		AddCodeT.setDocument(new JTextFieldLimit(4));
        		
                final JFrame frame = new JFrame("Class Manager");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                final JPanel panel = new JPanel(new BorderLayout(5,5));
                panel.setBorder( new TitledBorder("Class Manager") );

                JPanel Searchpanel = new JPanel();
                Searchpanel.setLayout(null);
                //Searchcomponent.setBorder(new TitledBorder("Search Component") );
                Searchpanel.setPreferredSize(new Dimension(100,100));
                
                SeasonCodeL.setLocation(5, 0);
                SeasonCodeT.setLocation(5, 20);
                
                SeasonDescriptionL.setLocation(75, 0);
                SeasonDescriptionT.setLocation(75,20);

                ClassCodeL.setLocation(175, 0);
                ClassCodeT.setLocation(175,20);
                
                ClassDescriptionL.setLocation(235,0);
                ClassDescriptionT.setLocation(235, 20);
                
                searchB.setBounds(40, 40, 80, 20);
                searchB.setLocation(0,80);
                searchB.setToolTipText("Search");
                
                seasoncodeL.setLocation(5, 10);
                classcodeL.setLocation(55, 10);
                AddT.setLocation(5, 30);
                AddCodeT.setLocation(55, 30);
                
                addB.setBounds(40,40,80,20);
                addB.setLocation(5, 60);
                addB.setToolTipText("Add");
                
                deleteB.setBounds(40, 40, 80, 20);
                deleteB.setLocation(85, 60);
                deleteB.setToolTipText("Delete");
                
                closeB.setBounds(40, 40, 80, 20);
                closeB.setLocation(285, 60);
                closeB.setToolTipText("Close");
                //closeB.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
                closeB.setBorder(new RoundedBorder(5));
                AddT.setToolTipText("Four position Alphanumeric");
                AddCodeT.setToolTipText(" Four Position Alphanumeric");
           
                Searchpanel.add(SeasonCodeL);
                Searchpanel.add(SeasonCodeT);
                Searchpanel.add(SeasonDescriptionL);
                Searchpanel.add(SeasonDescriptionT);
                Searchpanel.add(ClassDescriptionL);
                Searchpanel.add(ClassDescriptionT);
                Searchpanel.add(ClassCodeL);
                Searchpanel.add(ClassCodeT);
                Searchpanel.add(searchB);
                Searchpanel.add(newseasonl);
                Searchpanel.add(newseasont);

                closeB.addActionListener(new ActionListener() {
    				
    				public void actionPerformed(ActionEvent ae) {
    					
    					System.exit(0);

    				}
    				
    			});
                
                addB.addActionListener(new ActionListener(){
                	
                	public void actionPerformed(ActionEvent ae){
                		new SeasonEntry2().main(null);
                	}
                	
                });
                
               
                panel.add(Searchpanel, BorderLayout.NORTH);
 
                String[] header = {"Season", "Season Description", "Class", "Class Description"};
                
                //String[] a = new String[0];
                //String[] names = System.getProperties().stringPropertyNames().toArray(a);
                Object[][] data = {{"FA13", "FALL 2013", "MTA1","MATH A1",},
                				   {"SP13", "SPRING 2013", "MTA1", "MATH A1"},
                				   {"SP13", "SPRING 2013", "MTA2", "MATH A2"},
                				   {"SP13", "Spring 2013", "RDA1", "READING A1"},
                				   {"SP13", "SPRING 2013", "RDA2", "Reading A2"},
                				   {"SP13", "Spring 2013", "SCA1", "Science A1"},
                				   {"SP13", "SPRING 2013", "RDA3", "Reading A3"}
                };
                final JTable table = new JTable(data, header);
				table.setPreferredScrollableViewportSize(new Dimension(500, 70));
				table.setFillsViewportHeight(true);
				//table.setColumnSelectionAllowed(true);
				table.setRowSelectionAllowed(true);
				table.setAutoCreateRowSorter(true);
				//table.setBorder(BorderFactory.createCompoundBorder(table.getBorder(), BorderFactory.createEmptyBorder(0, 5, 0, 0)));
				
				

                JScrollPane scrollPane = new JScrollPane(table);
                
                JPanel addPanel = new JPanel();
                addPanel.setPreferredSize(new Dimension(100,100));
                addPanel.setLayout(null);

                addPanel.setBorder(new TitledBorder("Create New Season") );
                addPanel.add(seasoncodeL);
                addPanel.add(classcodeL);
                addPanel.add(AddT);
                addPanel.add(AddCodeT);
                addPanel.add(addB);
                addPanel.add(deleteB);
                addPanel.add(closeB);

                panel.add( scrollPane, BorderLayout.CENTER );
                
                
                panel.add(addPanel, BorderLayout.SOUTH);

                frame.setContentPane(panel);

                frame.pack();

                frame.setLocationRelativeTo(null);
                try {
                    // 1.6+
                    frame.setLocationByPlatform(false);// set location
                    frame.setSize(400, 400);
                    
                    //frame.setMinimumSize(frame.getSize());
                } catch(Throwable ignoreAndContinue) {
                }

                frame.setVisible(true);
            }
        };
        SwingUtilities.invokeLater(r);
    }
    
}